import geekIcon from './geekIcon.vue'
// 引入dayjs文件
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'

import hljs from 'highlight.js'
import 'highlight.js/styles/vs2015.css'
dayjs.extend(relativeTime)
dayjs.locale('zh-cn')

export default {
  install: function (Vue) {
    Vue.component(geekIcon.name, geekIcon)
    // 注册过滤器
    Vue.filter('relativeTime', (time) => {
      return dayjs(time).toNow()
    })

    Vue.directive('highlight', (el) => {
      const codeList = el.querySelectorAll('pre code')
      codeList.forEach((code) => {
        hljs.highlightElement(code)
      })
    })
  }
}
